package com.yun.controller;

import com.yun.pojo.Category;
import com.yun.pojo.User;
import com.yun.service.CategoryService;
import com.yun.unit.PageUnit;
import com.yun.unit.R;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //查询该用户的所有分类
    @Secured("ROLE_HEALTH_MANAGER")//设置角色 只有这个角色才能使用这个方法
    @PostMapping("/sel")
    public R sel(@RequestBody PageUnit pageUnit){
        return categoryService.selByUserId(pageUnit);
    }

    //假删文章
    @GetMapping("/del/{id}")
    public R del(@PathVariable Integer id){
        return categoryService.delById(id);
    }

    @GetMapping("/detail/{id}")
    public R detail(@PathVariable Integer id){
        return categoryService.detail(id);
    }
    //修改分类
    @PostMapping("/upd")
    public R upd(@RequestBody Category category){
        return categoryService.upd(category);
    }

    //新增分类
    @PostMapping("/ins")
    public R ins(@RequestBody Category category){
        return categoryService.ins(category);
    }

    //根据分类名称查询分类
    @PostMapping("/selname")
    public R selByName(@RequestBody PageUnit pageUnit){
        return categoryService.selByName(pageUnit);
    }

    //查看所有被假删了的分类
    @PostMapping("/selj")
    public R selByDel(@RequestBody PageUnit pageUnit){
        return categoryService.selByDel(pageUnit);
    }

    //还原或者删除
    @GetMapping("/updj/{id}/{del}")
    public R updByDel(@PathVariable Integer id,@PathVariable Integer del){
        return categoryService.updByDel(id,del);
    }
    @GetMapping("/all/{id}")
    public R selAll(@PathVariable Integer id){
        return categoryService.selAll(id);
    }
}
